/**
 * Created by dell on 2018/12/6.
 */
/*
完整的页面
 */

const http = require('http');
const path = require('path');
const fs = require('fs');

let readFile = (url,res)=>{
    fs.readFile(path.join(__dirname,'www',url),'utf8',(err,data)=>{
        if(err){
            res.end("server error");
        }else{
            res.end(data);
        }
    });
}


http.createServer((req,res)=>{
    // res.end(req.url);
    if(req.url.startsWith('/index')){
        readFile("index.html",res);
    }else if(req.url.startsWith('/about')){
        readFile("about.html",res);
    }else if(req.url.startsWith('/list')){
        readFile("list.html",res);
    }else{
        //设置响应类型和编码
        res.writeHead(200,{
            'content-Type':'text/plain; charset = utf8'
        });
        res.end('页面被狗狗叼走了');
    }
}).listen(3000);